/*
 * $Id: stdcli.h,v 1.8 2005-07-27 11:09:46 bacon Exp $
 */

#ifndef _XP_BAS_STDCLI_H_
#define _XP_BAS_STDCLI_H_

#include <xp/types.h>
#include <xp/macros.h>

#define XP_CLI_OPTNAME (1 << 0)
#define XP_CLI_OPTVAL  (1 << 1)

#define XP_CLI_ERROR_INVALID_OPTNAME  1
#define XP_CLI_ERROR_MISSING_OPTNAME  2
#define XP_CLI_ERROR_REDUNDANT_OPTVAL 3
#define XP_CLI_ERROR_MISSING_OPTVAL   4
#define XP_CLI_ERROR_MEMORY           5

typedef struct xp_cliopt_t xp_cliopt_t;
typedef struct xp_cli_t xp_cli_t;

struct xp_cliopt_t
{
	/* input */
	const xp_char_t* name;
	int requires;

	/* output - you don't have to initialize this field */
	xp_char_t* value;
};

struct xp_cli_t
{
	/* input */
	int (*errhandler) (
		const xp_cli_t* cli, int code, 
		const xp_char_t* qname, const xp_char_t* qval);
	const xp_char_t** optsta;
	const xp_char_t* optasn;
	xp_cliopt_t* opts;

	/* output - you don't have to initialize these fields */
	xp_char_t* verb;
	int nparams;
	xp_char_t** params;
};

#ifdef __cplusplus
extern "C" {
#endif

int xp_parsecli (int argc, xp_char_t* const argv[], xp_cli_t* cli);
void xp_clearcli (xp_cli_t* cli);

xp_char_t* xp_getcliverb (const xp_cli_t* cli);
xp_char_t* xp_getclioptval (const xp_cli_t* cli, const xp_char_t* opt);
xp_char_t* xp_getcliparams (const xp_cli_t* cli, int index);
int xp_getncliparams (const xp_cli_t* cli);

int xp_getopt (int argc, xp_char_t* const argv[],
	const xp_char_t* optstr, int* optidx, int long_only);


#ifdef __cplusplus
}
#endif

#endif
